"use strict";

/*
 * MikoPBX - free phone system for small business
 * Copyright © 2017-2023 Alexey Portnov and Nikolay Beketov
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along with this program.
 * If not, see <https://www.gnu.org/licenses/>.
 */

/**
 * The DebuggerInfo object is responsible for showing extra information by double ESC key press
 *
 * @module DebuggerInfo
 */
var DebuggerInfo = {
  $debugInfoDiv: $('#debug-info'),
  delta: 500,
  lastKeypressTime: 0,

  /**
   * Initializes the debugger info.
   */
  initialize: function initialize() {
    // Add CSS class to the debug info div
    DebuggerInfo.$debugInfoDiv.addClass('ui right very wide sidebar'); // Attach keydown event handler to the document

    window.$(document).on('keydown', function (event) {
      DebuggerInfo.keyHandler(event);
    });
  },

  /**
   * Updates the content of the debug info.
   * @param {string} newContent - The new content for the debug info.
   */
  UpdateContent: function UpdateContent(newContent) {
    DebuggerInfo.$debugInfoDiv.html(newContent);
  },

  /**
   * Shows the sidebar with the debug info.
   */
  showSidebar: function showSidebar() {
    // Check if debug info is available
    if (DebuggerInfo.$debugInfoDiv.html().length === 0) return; // Toggle the sidebar to show/hide

    DebuggerInfo.$debugInfoDiv.sidebar({
      transition: 'overlay',
      dimPage: false
    }).sidebar('toggle');
  },

  /**
   * Handles key events for the debugger info.
   * @param {Event} event - The keydown event.
   */
  keyHandler: function keyHandler(event) {
    // Double press of ESC key will show the debug information
    if (event.keyCode === 27) {
      var thisKeypressTime = new Date();

      if (thisKeypressTime - DebuggerInfo.lastKeypressTime <= DebuggerInfo.delta) {
        // Show the sidebar with debug info
        DebuggerInfo.showSidebar();
        thisKeypressTime = 0;
      } // Update the last keypress time


      DebuggerInfo.lastKeypressTime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gICAgICAgIGlmIChldmVudC5rZXlDb2RlID09PSAyNykge1xuICAgICAgICAgICAgbGV0IHRoaXNLZXlwcmVzc1RpbWUgPSBuZXcgRGF0ZSgpO1xuICAgICAgICAgICAgaWYgKHRoaXNLZXlwcmVzc1RpbWUgLSBEZWJ1Z2dlckluZm8ubGFzdEtleXByZXNzVGltZSA8PSBEZWJ1Z2dlckluZm8uZGVsdGEpIHtcbiAgICAgICAgICAgICAgICAvLyBTaG93IHRoZSBzaWRlYmFyIHdpdGggZGVidWcgaW5mb1xuICAgICAgICAgICAgICAgIERlYnVnZ2VySW5mby5zaG93U2lkZWJhcigpO1xuICAgICAgICAgICAgICAgIHRoaXNLZXlwcmVzc1RpbWUgPSAwO1xuICAgICAgICAgICAgfVxuICAgICAgICAgICAgLy8gVXBkYXRlIHRoZSBsYXN0IGtleXByZXNzIHRpbWVcbiAgICAgICAgICAgIERlYnVnZ2VySW5mby5sYXN0S2V5cHJlc3NUaW1lID0gdGhpc0tleXByZXNzVGltZTtcbiAgICAgICAgfVxuICAgIH0sXG59O1xuXG5cbi8vIGV4cG9ydCBkZWZhdWx0IERlYnVnZ2VySW5mbzsiXX0=